from pages.basePage4 import BasePage
from config.setting import host_port
import time

class AccountPage(BasePage):
    def __init__(self):
        BasePage.__init__(self)
        time.sleep(2)
        self.driver.get(f"http://{host_port}/SharedParkingPlace/admin/index.html")

    # 定位审核管理
    def examine(self):
        return self.driver.find_element_by_xpath('//div[@id="sm"]/div/div[2]')
    # 定位用户管理
    def user(self):
        return self.driver.find_element_by_xpath('//div[@id="sm"]/div/div[3]')

    # 定位账户管理
    def account(self):
        return self.driver.find_element_by_xpath('//div[@id="sm"]/div/div[5]')

    # 定位账户查看
    def check(self):
        return self.driver.find_element_by_id('_easyui_tree_15')
    # 定位平台交易记录查看
    def transaction_records(self):
        return self.driver.find_element_by_id('_easyui_tree_16')
    # 定位开始时间
    def begintime(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/input[1]')
    # 定位结束时间
    def endtime(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/input[2]')



    # 定位表单
    def iframe(self):
        return self.driver.find_element_by_id('testIframe')
    # 定位选择账户
    def acheck(self):
        return self.driver.find_element_by_id('datagrid-row-r1-2-0')

    # 定位修改按钮
    def mf_account(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[1]')
    # 定位状态栏
    def state(self):
        return self.driver.find_element_by_xpath('//*[@id="fm"]/div[2]/span/span/a')
    # 选择状态
    def select_sate(self,x):
        if x == 0:
            return self.driver.find_element_by_xpath('//div[@class="combo-panel panel-body panel-body-noheader"]/div[1]')
        elif x ==1:
            return self.driver.find_element_by_xpath('//div[@class="combo-panel panel-body panel-body-noheader"]/div[2]')
        elif x == 2:
            return self.driver.find_element_by_xpath('//div[@class="combo-panel panel-body panel-body-noheader"]/div[3]')
        elif x == 3 :
            return self.driver.find_element_by_xpath('//div[@class="combo-panel panel-body panel-body-noheader"]/div[4]')
        elif x == 4:
            return self.driver.find_element_by_xpath('//div[@class="combo-panel panel-body panel-body-noheader"]/div[5]')
        elif x == 5:
            return self.driver.find_element_by_xpath('//div[@class="combo-panel panel-body panel-body-noheader"]/div[6]')
    # 定位余额
    def balance(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input3"]')
    # 定位支付宝信息
    def zfb(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input4"]')
    # 定位修改
    def confirm(self):
        return self.driver.find_element_by_xpath('//div[@id="dlg-buttons"]/a[2]')
    # 定位支付宝信息
    def zfbxx(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[5]/div')

# 操作层
class AccountHandle(AccountPage):
    def __init__(self):
        AccountPage.__init__(self)

    # 点击审核
    def clk_exmine(self):
        self.examine().click()
    # 点击用户管理
    def clk_user(self):
        self.user().click()
    # 点击账户管理
    def clk_account(self):
        self.account().click()
    # 点击账户查看
    def click_check(self):
        self.check().click()

    # 切换表单
    def swith_frame(self):
        a = self.iframe()
        return self.driver.switch_to.frame(a)
    # 定位选择账户
    def clk_acheck(self):
        self.acheck().click()
    # 点击修改
    def clk_mf(self):
        self.mf_account().click()
    # 点击状态栏
    def clk_state(self):
        self.state().click()
    # 选择状态
    def clk_select_sate(self,x):

        self.select_sate(x).click()
    # 修改余额
    def send_balance(self,balance):
        input3=self.balance()
        input3.clear()
        input3.send_keys(balance)
    # 修改支付宝信息
    def send_zfb(self,zfb):
        input4=self.zfb()
        input4.clear()
        input4.send_keys(zfb)
#    点击修改
    def clk_confirm(self):
        self.confirm().click()
#    获取支付宝信息
    def get_zfb(self):
        Alipay=self.zfbxx().text
        return Alipay
#业务层
class AccountBusiness(AccountHandle):
    # 修改
    def mondfiy_account(self,x,balance,zfb):
        self.clk_exmine()
        self.clk_user()
        self.clk_account()
        self.click_check()
        self.swith_frame()
        self.clk_acheck()
        self.clk_mf()
        self.clk_state()
        time.sleep(2)
        self.clk_select_sate(x)
        self.send_balance(balance)
        self.send_zfb(zfb)
        self.clk_confirm()
        time.sleep(2)
        return self.get_zfb()
if __name__ == '__main__':
    a = AccountBusiness()
    m = a.mondfiy_account(2,9999,123456)
    print(m)




